package com.bbtShop.core.model;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 接口返回对象
 * @author 189****3725
 * @date 2020/10/13 15:04
 */
@Data
@AllArgsConstructor
public class ApiResponse<T> {

    private Integer code;

    private Boolean success;

    private String message;

    private T data;

    /**
     * 请求成功
     * @author 189****3725
     * @date 2020/10/13 15:04
     */
    public static <T> ApiResponse <T>success(T data) {
        return ApiResponse.success(200,"请求成功", data);
    }

    public static <T> ApiResponse <T>success() {
        return ApiResponse.success(200,"请求成功", null);
    }


    /**
     * 请求成功
     * @author 189****3725
     * @date 2020/10/13 15:04
     */
    public static <T> ApiResponse <T>success(Integer code,String message, T data) {
        return new ApiResponse<>(code,Boolean.TRUE, message, data);
    }

    /**
     * 请求失败
     * @author 189****3725
     * @date 2020/10/13 15:04
     */
    public static <T> ApiResponse <T> failed() {
        return ApiResponse.failed(500,"请求失败");
    }

    /**
     * 请求失败
     * @author 189****3725
     * @date 2020/10/13 15:04
     */
    public static <T> ApiResponse <T> failed(Integer code,String message) {
        return new ApiResponse<>(code,Boolean.FALSE, message, null);
    }
}